package com.brand.prisd.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.brand.prisd.R;
import com.brand.prisd.sp.MySharedPreferences;

/**
 * 广告页/欢迎页
 */
public class WelcomeActivity extends AppCompatActivity {

    private final int what = 2019;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        h.sendEmptyMessageDelayed(what, 3000);
//        int px = DensityUtil.dip2px(this, 20);
//        Logger.i(">>> "+px);
    }

    /**
     *
     * @return true 已经登录过  false 未登录过
     */
    private boolean isLogin() {
        return MySharedPreferences.Build(this).getBoolean("登录状态");
    }

    /**
     * 跳转到MainActivity
     */
    private void go2MainActivity() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

    /**
     * 跳转到SelectAccountAccountActivity
     */
    private void go2SelectAccountActivity() {
        startActivity(new Intent(this, SelectAccountActivity.class));
        finish();
    }

    private Handler h = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case what:
                    if (isLogin()) {
                        go2MainActivity();
                    } else {
                        go2SelectAccountActivity();
                    }
                    break;
            }
            return false;
        }
    });

}
